home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_05 / 8n05054a < prev    next >
Text File  |  1990-04-17  |  1KB  |  60 lines

  1. *****Listing 3*****
  2.  
  3. class Register {
  4. public:
  5.     // move point forward one character
  6.     virtual void go( Buffer &b, File &output)
  7.     {
  8.         if( b.isend() )
  9.             output.put( "?\n" );
  10.         else
  11.             b.next();
  12.     }
  13.  
  14.     // print character after point and move point forward
  15.     virtual void print( Buffer &b, File &output)
  16.     {
  17.         if( b.isend() )
  18.             output.put( "?\n" );
  19.         else
  20.             output.put( b.geta());
  21.         go();   // Register::go()
  22.     }
  23.  
  24.     // insert after point
  25.     virtual void insert( Buffer &b, File &input)
  26.     {
  27.         int c;
  28.         int prev = '\n';
  29.         while( !input.iseof() ) {
  30.             c = input.get();
  31.             if( (prev == '\n') && (c == '.') )
  32.                 if( input.peek() == '\n' ) {
  33.                     input.get();
  34.                     break;
  35.                 }
  36.             b.putb( c);
  37.             prev = c;
  38.         }
  39.     }
  40.  
  41.     virtual void del( Buffer &b, Buffer &kbuf, File &output)
  42.     {
  43.         if( b.isend() )
  44.             output.put( "?\n" );
  45.         else {
  46.             // need to capture deletion into kill buf
  47.             // empty out the kbuf ...
  48.             for( kbuf.begin(); !kbuf.isend(); kbuf.next())
  49.                 kbuf.dela();
  50.             kbuf.putb( b.dela());
  51.         }
  52.     }
  53.  
  54.     virtual void put( Buffer &b, Buffer &kbuf) 
  55.         { b.putb( kbuf.geta()); }
  56.  
  57.     // no need for data members. defaults are implicit!
  58. };
  59.  
  60.